package file_operation;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * 输入文件名并创建对应文件
 * */
public class CreateFile {
    public static boolean createFile(File file) throws IOException {
        if (!file.exists()) {
            File parent = file.getParentFile();
            if (!parent.exists())
                parent.mkdirs();
            return file.createNewFile();
        }
        return false;
    }

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        File file;
        while (true) {
            String filename = scanner.nextLine();
            file = new File(filename);
            System.out.println(file.isFile());
            boolean tf = createFile(file);
            if (tf) {
                System.out.println("已成功创建该文件");
                break;
            }
            else
                System.out.println("文件已存在，请重新输入");
        }
    }
}
